<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/include/head.jsp" %>
<script type="text/javascript">
var dialog = frameElement.dialog;
$(function() {
	var opts = dialog.dialog("options");
	 var defaultOpts = {
			title:null, 
			toolbar: null,
	        height: '100%', 
	        nowrap: false, 
	        striped: true, 
	        border: true, 
	        fitColumns:true,
	        checkOnSelect:true,
	        multiSort:false,
	        collapsible:false,//是否可折叠的 
	        fit: true,//自动大小 
	        //sortName: 'periodType', 
	        //sortOrder: 'desc', 
	        remoteSort:false,  
	        idField:'id', 
	        singleSelect:!opts.isMultiSelect,//是否单选 
	        pagination:false,//分页控件 
	        rownumbers:true,//行号 
	        frozenColumns:[[ 
	            {field:'id',checkbox:true} 
	        ]], 
		    url:'${ctx}/platform/product/listAllData.do',
		    columns:[[
		                {field:'code',title:'产品编码',width:100,sortable:true},
		                {field:'name',title:'产品名称',width:100,sortable:true},
		                {field:'pprice',title:'进价',width:100,sortable:true},
		                {field:'sprice',title:'售价',width:100,sortable:true},
		                {field:'unit',title:'单位',width:100,sortable:true},
		                {field:'spec',title:'规格型号',width:100,sortable:true}
		            ]],
		    onDblClickRow:function(index,row){
		    	var ids = row.id;
				var names = row.name;
				var rows  = new Array();
				if(opts.isMultiSelect)
				{
					rows.push(row);					
				}
				else
				{
					rows = row;
				}
				if($.isFunction(dialog.dialog('options').callback))
				{
					dialog.dialog('options').callback({ids:ids,names:names,data:rows});
				}
				 closeDialog();
		    }
		};
	
	 $("#dg_scoredetail").datagrid(defaultOpts);
});

function select(){
	var opts = dialog.dialog("options");
	var selectedRow = $("#dg_scoredetail").datagrid('getChecked');
	if(selectedRow.length <= 0)
	{
		 $.messager.alert("验证结果", "请选择数据", 'error', function () {
         });
		 return;
	}
    if(selectedRow.length > 0){
    	var ids = '';
		var names = '';
		for(var i = 0 ; i < selectedRow.length ; i++){
			ids += ','+ selectedRow[i].id;
			names += ','+ selectedRow[i].name;
		}
		ids = ids.substring(1);
		names = names.substring(1);
		var rows = opts.isMultiSelect?selectedRow:selectedRow[0];
		if($.isFunction(dialog.dialog('options').callback))
		{
			dialog.dialog('options').callback({ids:ids,names:names,data:rows});
		}
    }

    closeDialog();
}
function closeDialog()
{
	dialog.dialog('close');
}


</script>
<div id="cc" class="easyui-layout" style="width:100%;height:100%;">   
	<div data-options="region:'center'" style="padding:5px;background:#eee;height:200px;">
		<table id="dg_scoredetail"> </table>
	</div>
	<div data-options="region:'south'" style="height:35px;text-align: center;padding-top: 5px">
          <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="select()">确定</a>  
          <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="closeDialog()">取消</a>  
	</div>
</div>
 
<%@include file="/include/foot.jsp" %>